package com.jinzhi.jzweb.controller.backstage;

import com.baomidou.mybatisplus.plugins.Page;
import com.jinzhi.common.annotation.Log;
import com.jinzhi.common.utils.Result;
import com.jinzhi.jzapi.domain.UserDO;
import com.jinzhi.jzweb.domain.param.UserQuery;
import com.jinzhi.jzweb.domain.vo.home.SysUserVo;
import com.jinzhi.jzweb.service.JazSysUserService;
import io.swagger.annotations.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 *  前端控制器
 * </p>
 * @author JingChangTian
 * @since 2023-06-16
 */
@Controller
@RequestMapping("/userManagement")
@Api(value = "用户管理", tags = "用户管理")
public class SysUserController {

    /**
     * 业务层，充值
     */
    private final JazSysUserService jazSysUserService;

    public SysUserController(JazSysUserService jazSysUserService) {
        this.jazSysUserService = jazSysUserService;
    }


    @ApiOperation(value = "分页查询用户信息", notes = "分页查询用户信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "UserQuery", value = "UserQuery", required = true, dataType = "UserQuery"),
    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功"),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @ResponseBody
    @PostMapping(value = "/getOrderRecharge")
    @RequiresPermissions("sys:userManagement:list")
    public Result<Page<UserDO>> getOrderRecharge(@RequestBody UserQuery userQuery){
       return Result.ok(jazSysUserService.getPageUser(userQuery));
    }


    @ApiOperation(value = "根据用户id查询用户详情", notes = "根据用户id查询用户详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "UserQuery", value = "UserQuery", required = true, dataType = "UserQuery"),
    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功"),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @ResponseBody
    @PostMapping(value = "/getUserDetails")
    public Result<SysUserVo> getUserDetails(@RequestBody UserQuery userQuery){
        return Result.ok(jazSysUserService.getUserDetails(userQuery));
    }

    @Log(value = "删除用户",sysModule = 1,operationType = 2)
    @ApiOperation(value = "根据id删除用户信息", notes = "根据id删除用户信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "id"),
    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功"),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @ResponseBody
    @PostMapping(value = "/deletedByUserId")
    @RequiresPermissions("sys:userManagement:remove")
    public Result<Object> deletedByUserId(@RequestParam("id") Long id){
        return jazSysUserService.deletedByUserId(id);
    }


    @Log(value = "修改用户信息",sysModule = 1,operationType = 3)
    @ApiOperation(value = "根据用户id修改用户信息", notes = "根据用户id修改用户信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "UserDO", value = "UserDO", required = true, dataType = "UserDO"),
    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功"),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @ResponseBody
    @PostMapping(value = "/updateUser")
    public Result<String> updateUser(@RequestBody UserDO userDO){
        Boolean aBoolean = jazSysUserService.updateById(userDO);
        return aBoolean ? Result.ok() : Result.fail();
    }


    @ApiOperation(value = "后台根据用户id修改用户积分", notes = "后台根据用户id修改用户积分")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "UserDO", value = "UserDO", required = true, dataType = "UserDO"),
    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功"),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @ResponseBody
    @PostMapping (value = "/updateCurrentById")
    public Result<String> updateCurrentById(@RequestBody UserDO userDO){
        Boolean aBoolean = jazSysUserService.updateCurrentById(userDO);
        return aBoolean ? Result.ok() : Result.fail();
    }


    @ApiOperation(value = "用户查询列表页面入口", notes = "用户查询列表页面入口")
    @ApiImplicitParams({
    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功"),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @GetMapping("/user")
    @RequiresPermissions("sys:userManagement:list")
    public String user(){
        return "jzweb/userManagement/userManagement";
    }


    @ApiOperation(value = "用户详情页面入口", notes = "用户详情页面入口")
    @ApiImplicitParams({
    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功"),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @GetMapping("/info")
    public String info(){
        return "jzweb/userManagement/info";
    }


    @ApiOperation(value = "用户详情页面入口", notes = "用户详情页面入口")
    @ApiImplicitParams({
    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功"),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @GetMapping("/add")
    public String add(){
        return "jzweb/userManagement/add";
    }



}
